function HandlePageWageVerified(gui, operator, now, options) {
  this._gui = gui;
  this._operator = operator;
  this._now = now;
  this._options = options;

  this._createElements();
};

HandlePageWageVerified.prototype._createElements = function() {
  var _self = this;
  this._popupBox = new PopupBox();
  this._popupBox2 = new PopupBox2();
  this._selects = [];
  this._exp = Expense.instance();
  this._exp.payDate = '';
  this._search = DlmanageUtils.acctExpenseSearch();
  
  tr = this._gui.mains.insertRow(-1);
  td = tr.insertCell(-1);
  td.style.backgroundColor = '#fff';
  td.colSpan = 8;
  td.appendChild(DOMUtils.getLoadingImage());
  
  this._loadData();
};

HandlePageWageVerified.prototype._loadData = function() {
  this._payees = null;
  this._expenses = null;
  this._particulars = null;
  this._parameters = null;
  this._retrieveExpenses(1);
  this._retrievePayees();
  this._retrieveParticulars();
};

HandlePageWageVerified.prototype._verifyData = function() {
  if (this._expenses && this._payees && this._particulars) {
    this._updateElements();
  }
};

HandlePageWageVerified.prototype._retrieveExpenses = function(page, condition, from, to, pfrom, pto, pos) {
  var _self = this;
  var cond = '(d.status = 0 OR d.status = 1)' + ' AND (d.particular LIKE \'%Wage%\')';
  var args = ((condition) ?  'c=' + condition + ' AND ' + cond : 'c=' + cond) + '&p=' + page  + ((from) ?  '&from=' + from : '') + ((to) ?  '&to=' + to : '') + '&s=' + DlmanageUtils.number + ((pfrom) ?  '&pfrom=' + pfrom : '') + ((pto) ?  '&pto=' + pto : '');
  new RequestUtils()._custom('acctexpenses', args, function(result, params) { _self._expenses = result.data;
                                                                              _self._parameters = result;
                                                                              _self._verifyData.call(_self);
                                                                            }, { pos: (pos) ? pos : null });
};

HandlePageWageVerified.prototype._retrievePayees = function() {
  var _self = this;
  new RequestUtils()._read('ipayee', null, null, null, null, 'd.name', null, function(result, params) { _self._payees = result.data;
                                                                                                        _self._verifyData.call(_self);
                                                                                                      }, null);
};

HandlePageWageVerified.prototype._retrieveParticulars = function() {
  var _self = this;
  new RequestUtils()._read('iparticular', null, null, null, null, 'd.name', null, function(result, params) { _self._particulars = result.data;
                                                                                                             _self._verifyData.call(_self);
                                                                                                           }, null);
};

HandlePageWageVerified.prototype._updateElements = function() {
  var _self = this;
  DlmanageUtils.clear(this._gui.search);
  DOMUtils.removeChildElements(this._gui.pagination);
  DlmanageUtils.clear(this._gui.add);
  DOMUtils.removeTableRows(this._gui.mains, 0);

  this._exp.userTrackId = this._operator.trackId;
  this._exp.userAccount = this._operator.account;
  this._gui.add.createdDate.appendChild(document.createTextNode(SimpleDate.format(this._now)));
  this._exp.createdDate = this._now;
  
  this._gui.add.paidDate.value = (this._exp.payDate) ? SimpleDate.format(this._exp.payDate) : '';
  this._gui.add.paidDate.onclick = function() { var context = this;
                                                _self._changeDate.call(_self, this, _self._exp.payDate, function(sd) { _self._exp.payDate = sd; context.focus(); }, false);
                                                return false;
                                              };
  this._gui.add.payee.who.options[this._gui.add.payee.who.options.length] = new Option('');
  for (var i = 0, il = this._payees.length; i < il; i++) {
    var payee = this._payees[i];
    var option = new Option(payee.name);
    this._gui.add.payee.who.options[this._gui.add.payee.who.options.length] = option;
    if (option.text == this._exp.payee){
      this._gui.add.payee.who.selectedIndex = this._gui.add.payee.who.options.length - 1;
    }
  }
  if (this._payees.length > 0) {
    this._exp.payee = this._gui.add.payee.who.options[this._gui.add.payee.who.selectedIndex].text;
    this._gui.add.payee.who.onchange = function() { _self._exp.payee = this.options[this.selectedIndex].text; };
  }
  this._gui.add.payee.add.onclick = function() { var object = IPayee.instance();
                                                 var div = document.createElement('div');
                                                 var func1 = function() { _self._popupBox._close();
                                                                          _self._exp.payee = object.name;
                                                                          new RequestUtils()._write('ipayee', [object], [], function() { _self._retrievePayees.call(_self); }, { pos: DOMUtils.findPos(_self._gui.add.payee.add) });
                                                                        };
                                                 var func2 = function() { _self._popupBox._close();
                                                                        };
                                                 MiscUtils.dialog(_self._popupBox, DOMUtils.findPos(this), div, func1, func2, { ok: 'Add' });
                                                 new DialogIObject(div, object, { name: 'ipayee', title: 'Payees' });
                                               };

  this._gui.add.particulars.particular.options[this._gui.add.particulars.particular.options.length] = new Option('');
  for (var i = 0, il = this._particulars.length; i < il; i++) {
   var particular = this._particulars[i];
   if (particular.name.indexOf('Wage') != -1) {
     var option = new Option(particular.name);
     this._gui.add.particulars.particular.options[this._gui.add.particulars.particular.options.length] = option;
     if (option.text == this._exp.particular){
       this._gui.add.particulars.particular.selectedIndex = this._gui.add.particulars.particular.options.length - 1;
     }
   }
 }
 if (this._particulars.length > 0) {
   this._exp.particular = this._gui.add.particulars.particular.options[this._gui.add.particulars.particular.selectedIndex].text;
   this._gui.add.particulars.particular.onchange = function() { _self._exp.particular = this.options[this.selectedIndex].text; };
 }
 this._gui.add.particulars.add.onclick = function() { var object = IParticular.instance();
                                                      var div = document.createElement('div');
                                                      var func1 = function() { _self._popupBox._close();
                                                                               _self._exp.particular = object.name;
                                                                               new RequestUtils()._write('iparticular', [object], [], function() { _self._retrieveParticulars.call(_self); }, { pos: DOMUtils.findPos(_self._gui.add.particulars.add) });
                                                                             };
                                                      var func2 = function() { _self._popupBox._close();
                                                                             };
                                                      MiscUtils.dialog(_self._popupBox, DOMUtils.findPos(this), div, func1, func2, { ok: 'Add' });
                                                      new DialogIObject(div, object, { name: 'iparticular', title: 'Particulars' });
                                                    };
  this._gui.add.amount.value = this._exp.amount;
  this._gui.add.amount.onchange = function() { _self._exp.amount = this.value; };
  this._gui.add.note.value = this._exp.note;
  this._gui.add.note.onchange = function() { _self._exp.note = this.value; };
  
  this._gui.add.add.onclick = function() { if (!_self._exp.payDate) {
                                             window.alert('请填写付款时间');
                                             return;
                                           } else if(!_self._exp.payee) {
                                             window.alert('请选择收款人');
                                             return;
                                           } else if(!_self._exp.particular) {
                                             window.alert('请选择支付项目');
                                             return;
                                           } else if (_self._exp.amount== '' || _self._gui.add.amount.value == 0) {
                                             window.alert('数值不能为\'' + _self._gui.add.amount.value + '\'');
                                             return;
                                           } else {
                                             _self._exp.status = 1;
                                             new RequestUtils()._write('expense', [_self._exp], [], function() { location.reload(); }, { pos: DOMUtils.findPos(this) });
                                           }
                                         };
  if (this._expenses.length == 0) {
    tr = this._gui.mains.insertRow(-1);
    tr.className = 'roweven';
    td = tr.insertCell(-1);
    td.colSpan = 8;
    td.style.height = '24px';
    td.style.textAlign = 'center';
    td.appendChild(document.createTextNode('N/A'));
  }
  
  for (var i = 0, il = this._expenses.length; i < il; i++) {
    var expense = this._expenses[i];
    tr = this._gui.mains.insertRow(-1);
    tr.className = (tr.rowIndex % 2 == 0) ? 'roweven' : 'rowodd';
    
    td = tr.insertCell(-1);
    td.style.width = '80px';
    td.style.textAlign = 'center';
    td.appendChild(document.createTextNode(SimpleDate.format(expense.createdDate)));
    
    td = tr.insertCell(-1);
    td.style.width = '80px';
    td.style.textAlign = 'center';
    td.appendChild(document.createTextNode(SimpleDate.format(expense.payDate)));
    
    td = tr.insertCell(-1);
    td.style.textAlign = 'left';
    td.style.width = '122px';
    td.style.padding = '0 0 0 12px';
    td.appendChild(document.createTextNode(expense.payee));
    
    td = tr.insertCell(-1);
    td.style.textAlign = 'left';
    td.style.width = '131px';
    td.style.padding = '0 0 0 12px';
    td.appendChild(document.createTextNode(expense.particular));
    
    if (expense.status == 0) {
      td = tr.insertCell(-1);
      td.style.textAlign = 'center';
      td.style.width = '75px';
      var input = DOMUtils.createInput('', '', 'text', (expense.amount == 0) ? '' : expense.amount, null);
      input.style.width = '65px';
      input.style.borderLeft='solid 1px #d2c4b9';
      input.style.borderTop= 'solid 1px #d2c4b9';
      input.style.borderRight= 'solid 1px #fff';
      input.style.borderBottom= 'solid 1px #fff';
      input._expense = expense;
      input.onchange = function() { this._expense.amount = this.value; };
      td.appendChild(input);
  
      td = tr.insertCell(-1);
      td.style.textAlign = 'center';
      td.style.width = '220px';
      var input = DOMUtils.createInput('', '', 'text', expense.note, null);
      input.style.width = '240px';
      input.style.borderLeft='solid 1px #d2c4b9';
      input.style.borderTop= 'solid 1px #d2c4b9';
      input.style.borderRight= 'solid 1px #fff';
      input.style.borderBottom= 'solid 1px #fff';
      input._expense = expense;
      input.onchange = function() { this._expense.note = this.value; };
      td.appendChild(input);
    } else {
      td = tr.insertCell(-1);
      td.style.textAlign = 'left';
      td.style.padding = '0 0 0 12px';
      td.style.width = '63px';
      td.appendChild(document.createTextNode('$' + expense.amount));
  
      td = tr.insertCell(-1);
      td.style.textAlign = 'left';
      td.style.padding = '0 0 0 12px';
      td.style.width = '220px';
      if (expense.note.length > 0) {
        td.appendChild(document.createTextNode((expense.note.length > 30) ? expense.note.substring(0, 30) + '...' : expense.note));
        var a = document.createElement('a');
        a.href = '#';
        a._expense = expense;
        a.appendChild(document.createTextNode('All'));
        a.onclick = function() { func1 = function() { _self._popupBox._close(); };
                                 var pos = DOMUtils.findPos(this);
                                 var div = document.createElement('div');
                                 div.appendChild(MiscUtils.span('\n' + this._expense.note));
                                 MiscUtils.dialog(_self._popupBox, pos, div, func1, null);
                                 return false;
                                };
        if (expense.note.length > 30) {
          td.appendChild(a);
        }
      } else {
        td.appendChild(document.createTextNode('(none)'));
      }
    }
    td = tr.insertCell(-1);
    td.style.textAlign = 'center';
    td.style.width = '100px';
    var confirm = DOMUtils.createInput('', '', 'button', 'Confirm', null);
    confirm.style.margin = '0 5px 0 0';
    confirm._expense = expense;
    confirm.onclick = function() { this._expense.status = 1;
                                   new RequestUtils()._write('expense', [this._expense], [], function(result,params) { if (result) { _self._retrieveExpenses(_self._parameters.page, _self._parameters.condition); }; }, { pos: DOMUtils.findPos(this) });
                                 };
    if (expense.status == 0) {
      td.appendChild(confirm);
    }
    
    var remove = document.createElement('img');
    remove.src = 'images/common/delete.png';
    remove.style.cursor = 'pointer';
    remove._expense = expense;
    remove.onclick = function() { var pos = DOMUtils.findPos(this);
                                  var div = document.createElement('div');
                                  var expense = this._expense
                                  var func1 = function() { expense.status = -1;
                                                           expense.cancelledDate = _self._now;
                                                           expense.cancelledOperator = _self._operator.account;
                                                           expense.cancelledMessage = expense._text;
                                                           new RequestUtils()._write('expense', [expense], [], function() { _self._retrieveExpenses(1); }, { pos: pos });
                                                           _self._popupBox2._close();
                                                         };
                                  var func2 = function() { _self._popupBox2._close(); };
                                  MiscUtils.dialog(_self._popupBox2, pos, div, func1, func2, {t: 'Cancel Reason'});
                                  new DialogInput(div, expense, { title: '' });
                                  return false;
                                };
    td.appendChild(remove);
  }
  
  Pagination.makePagedResults(this._gui.pagination, this._parameters.page, this._parameters.total, this._parameters.size, function(page, condition) { _self._retrieveExpenses.call(_self, page, _self._parameters.condition); }, this, document);
  
  this._expenseSearch(this._gui, function(condition, from, to, pfrom, pto, pos) { _self._retrieveExpenses.call(_self, 1, condition, from, to, pfrom, pto, pos); });
};

HandlePageWageVerified.prototype._expenseSearch = function(gui, callbackFunc) {
  var _self = this;
  this._callbackFunc = callbackFunc;
  gui.search.cdateFrom.value = (this._search.cdateFrom) ? SimpleDate.format(this._search.cdateFrom) : '';
  gui.search.cdateFrom.onclick = function() { var context = this;
                                              _self._changeDate.call(_self, this, _self._search.cdateFrom, function(sd) { _self._search.cdateFrom = sd; context.focus(); }, false);
                                              return false;
                                            };
  gui.search.cdateFrom.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
                                                  if (code == 13) {
                                                    _self._callbackFunc.call(_self, _self._toString(_self._search), (_self._search.cdateFrom) ? JSON.stringify(_self._search.cdateFrom) : null, (_self._search.cdateTo) ? JSON.stringify(_self._search.cdateTo) : null, (_self._search.pdateFrom) ? JSON.stringify(_self._search.pdateFrom) : null, (_self._search.pdateTo) ? JSON.stringify(_self._search.pdateTo) : null, DOMUtils.findPos(this));
                                                  }
                                                };
  gui.search.cdateTo.value = (this._search.cdateTo) ? SimpleDate.format(this._search.cdateTo) : '';
  gui.search.cdateTo.onclick = function() { var context = this;
                                            _self._changeDate.call(_self, this, _self._search.cdateTo, function(sd) { _self._search.cdateTo = sd; context.focus(); }, false);
                                            return false;
                                         };
  gui.search.cdateTo.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
                                                if (code == 13) {
                                                  _self._callbackFunc.call(_self, _self._toString(_self._search), (_self._search.cdateFrom) ? JSON.stringify(_self._search.cdateFrom) : null, (_self._search.cdateTo) ? JSON.stringify(_self._search.cdateTo) : null, (_self._search.pdateFrom) ? JSON.stringify(_self._search.pdateFrom) : null, (_self._search.pdateTo) ? JSON.stringify(_self._search.pdateTo) : null, DOMUtils.findPos(this));
                                               }
                                             };
                                             
  gui.search.pdateFrom.value = (this._search.pdateFrom) ? SimpleDate.format(this._search.pdateFrom) : '';
  gui.search.pdateFrom.onclick = function() { var context = this;
                                              _self._changeDate.call(_self, this, _self._search.pdateFrom, function(sd) { _self._search.pdateFrom = sd; context.focus(); }, false);
                                              return false;
                                            };
  gui.search.pdateFrom.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
                                                  if (code == 13) {
                                                    _self._callbackFunc.call(_self, _self._toString(_self._search), (_self._search.cdateFrom) ? JSON.stringify(_self._search.cdateFrom) : null, (_self._search.cdateTo) ? JSON.stringify(_self._search.cdateTo) : null, (_self._search.pdateFrom) ? JSON.stringify(_self._search.pdateFrom) : null, (_self._search.pdateTo) ? JSON.stringify(_self._search.pdateTo) : null, DOMUtils.findPos(this));
                                                  }
                                                };
  gui.search.pdateTo.value = (this._search.pdateTo) ? SimpleDate.format(this._search.pdateTo) : '';
  gui.search.pdateTo.onclick = function() { var context = this;
                                            _self._changeDate.call(_self, this, _self._search.pdateTo, function(sd) { _self._search.pdateTo = sd; context.focus(); }, false);
                                            return false;
                                         };
  gui.search.pdateTo.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
                                                if (code == 13) {
                                                  _self._callbackFunc.call(_self, _self._toString(_self._search), (_self._search.cdateFrom) ? JSON.stringify(_self._search.cdateFrom) : null, (_self._search.cdateTo) ? JSON.stringify(_self._search.cdateTo) : null, (_self._search.pdateFrom) ? JSON.stringify(_self._search.pdateFrom) : null, (_self._search.pdateTo) ? JSON.stringify(_self._search.pdateTo) : null, DOMUtils.findPos(this));
                                               }
                                             };
  gui.search.payee.options[gui.search.payee.options.length] = new Option('');
  for (var i = 0, il = this._payees.length; i < il; i++) {
    var payee = this._payees[i];
    var option = new Option(payee.name);
    gui.search.payee.options[gui.search.payee.options.length] = option;
    if (option.text == this._search.payee){
      gui.search.payee.selectedIndex = gui.search.payee.options.length - 1;
    }
  }
  if (this._payees.length > 0) {
    this._search.payee = gui.search.payee.options[gui.search.payee.selectedIndex].text;
    gui.search.payee.onchange = function() { _self._search.payee = this.options[this.selectedIndex].text; };
  }
  
  gui.search.particular.options[gui.search.particular.options.length] = new Option('');
  for (var i = 0, il = this._particulars.length; i < il; i++) {
    var particular = this._particulars[i];
    var option = new Option(particular.name);
    gui.search.particular.options[gui.search.particular.options.length] = option;
    if (option.text == this._search.particular){
      gui.search.particular.selectedIndex = gui.search.particular.options.length - 1;
    }
  }
  if (this._particulars.length > 0) {
    this._search.particular = gui.search.particular.options[gui.search.particular.selectedIndex].text;
    gui.search.particular.onchange = function() { _self._search.particular = this.options[this.selectedIndex].text; };
  }
  
  gui.search.amount.value = this._search.amount;
  gui.search.amount.onkeydown = function() { _self._search.amount = this.value; };
  gui.search.amount.onchange = function() { _self._search.amount = this.value; };
  gui.search.amount.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
                                               if (code == 13) {
                                                 _self._callbackFunc.call(_self, _self._toString(_self._search), (_self._search.cdateFrom) ? JSON.stringify(_self._search.cdateFrom) : null, (_self._search.cdateTo) ? JSON.stringify(_self._search.cdateTo) : null, (_self._search.pdateFrom) ? JSON.stringify(_self._search.pdateFrom) : null, (_self._search.pdateTo) ? JSON.stringify(_self._search.pdateTo) : null, DOMUtils.findPos(this));
                                               }
                                             };
  this._search.note = gui.search.note.value;
  gui.search.note.value = this._search.note;
  gui.search.note.onkeydown = function() { _self._search.note = this.value; };
  gui.search.note.onchange = function() { _self._search.note = this.value; };
  gui.search.note.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
                                              if (code == 13) {
                                                _self._callbackFunc.call(_self, _self._toString(_self._search), (_self._search.cdateFrom) ? JSON.stringify(_self._search.cdateFrom) : null, (_self._search.cdateTo) ? JSON.stringify(_self._search.cdateTo) : null, (_self._search.pdateFrom) ? JSON.stringify(_self._search.pdateFrom) : null, (_self._search.pdateTo) ? JSON.stringify(_self._search.pdateTo) : null, DOMUtils.findPos(this));
                                              }
                                            };
  gui.search.note.onkeyup = function() { if (gui.search.note.value.length == 0) {
                                           _self._popupBox._close();
                                         } else {
                                           var div = document.createElement('div');
                                           var pos1 = DOMUtils.findPos(gui.search.note);
                                           var pos = [pos1[0] + 1, pos1[1] + 82];
                                           var query = "SELECT e.note FROM ns_Expense as e WHERE 1 = 1 AND " + '((e.note LIKE \'%' + gui.search.note.value + '%\'))' + " ";
                                           MiscUtils.dialog(_self._popupBox, pos, div, null, null, {pop: true});
                                           new DialogSearchResult(div, gui.search.note, { query: query, popupBox: _self._popupBox, callbackFunc: function() { _self._updateElements();}, width: 195});
                                         }
                                       };
  gui.search.search.onclick = function() { _self._callbackFunc.call(_self, _self._toString(_self._search), (_self._search.cdateFrom) ? JSON.stringify(_self._search.cdateFrom) : null, (_self._search.cdateTo) ? JSON.stringify(_self._search.cdateTo) : null, (_self._search.pdateFrom) ? JSON.stringify(_self._search.pdateFrom) : null, (_self._search.pdateTo) ? JSON.stringify(_self._search.pdateTo) : null, DOMUtils.findPos(this));
                                         };
};

HandlePageWageVerified.prototype._toString = function(search) {
  var str = '1 = 1';
  
  str += (search.payee == '') ? '' : ' AND (d.payee LIKE \'%' + search.payee + '%\')';
  str += (search.particular == '') ? '' : ' AND (d.particular LIKE \'%' + search.particular + '%\')';
  str += (search.amount == '') ? '' : ((isNaN(search.amount)) ? ' AND 1 = 0' : ' AND (d.amount=\'' + search.amount + '\')');
  str += (search.note == '') ? '' : ' AND (d.note LIKE \'%' + search.note + '%\')';
  
  return str;
};

HandlePageWageVerified.prototype._changeDate = function(label, currentDate, onChangeFunc, showTime) {
  var _self = this;
  this._wContainer = document.createElement('div');
  this._wContainer.style.left = DOMUtils.findPos(label)[0] + 'px';
  this._wContainer.style.top = DOMUtils.findPos(label)[1] + 'px';
  this._popupBox._open(this._wContainer, { pos: DOMUtils.findPos(label) });
  
  var ds = new DateSelect(currentDate, null, { container: this._wContainer, showTime: showTime });
  ds._selectFunc = function(sd) { _self._selectDate.call(_self, sd, label, onChangeFunc, showTime); };
};

HandlePageWageVerified.prototype._selectDate = function(sd, label, onChangeFunc, showTime) {
  
  onChangeFunc(sd);
  this._showDate(sd, label, showTime);
  this._popupBox._close();
};

HandlePageWageVerified.prototype._showDate = function(sd, label, showTime) {
  if (sd) { 
    label.value = SimpleDate.format(sd, showTime);
  } else {
    label.value = '';
  }
};